<?php

namespace App\V3\Api\Controllers;

use App\V3\Api\Services\SalesReturnService;
use App\V3\Api\Services\SellService;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;
use App\V3\Api\Services\StorageManageService;

class CommonDetailController extends Controller
{
    //销售单详细-without token
    public function sellFind(Request $request)
    {
        //参数验证
        $validator = Validator::make($request->except('role_id'), [
            'id' =>'required|integer',//销售单主键id
        ]);

        if ($info = $validator->errors()->first()) {
            return response()->json([
                'code' => 1,
                'msg' => $info,
                'data' => '',
            ]);
        }

        return success(SellService::detail($request->id));
    }

    //退货单详细-without token
    public function salesReturnFind(Request $request)
    {
        //参数验证
        $validator = Validator::make($request->except('role_id'), [
            'id' =>'required|integer',//销售单主键id
        ],[
            'id.required' => '退货单id缺失'
        ]);

        if ($info = $validator->errors()->first()) {
            return response()->json([
                'code' => 1,
                'msg' => $info,
                'data' => '',
            ]);
        }

        return response()->json(SalesReturnService::find($request->id));
    }
    
    public function readGoodsIdInfo(Request $request){
        //参数验证
        $validator = Validator::make($data=$request->all(), [
            'goods_id' =>'required|integer',//销售单主键id
        ],[
            'goods_id.required' => '商品id缺失'
        ]);
    
        if ($info = $validator->errors()->first()) {
            return response()->json([
                'code' => 1,
                'msg' => $info,
                'data' => '',
            ]);
        }
    
        return success(StorageManageService::readGoodsIdInfo($data));
    }
}
